package com.fastadmin.controller;

import cn.hutool.system.*;
import cn.hutool.system.oshi.OshiUtil;
import com.fastadmin.mapper.impl.GongGaoMapper;
import com.fastadmin.pojo.FastParam;
import com.fastadmin.pojo.GongGao;
import com.xphsc.easyjdbc.page.PageInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import oshi.hardware.GlobalMemory;

@Controller
@RequiredArgsConstructor
public class DashboardController {


    private final  GongGaoMapper gongGaoMapper;

    /**
     * 控制台主页
     *
     * @return
     */
    @GetMapping("/sys/dashboard/index")
    public String sysDashboardIndex(Model model) {


        long currentPID = SystemUtil.getCurrentPID();
        JavaInfo javaInfo = SystemUtil.getJavaInfo();
        OsInfo osInfo = SystemUtil.getOsInfo();
        HostInfo hostInfo = SystemUtil.getHostInfo();
        long total = OshiUtil.getMemory().getTotal();
        long available = OshiUtil.getMemory().getAvailable();
        JvmSpecInfo jvmSpecInfo = new JvmSpecInfo();
        model.addAttribute("currentPID", currentPID);
        model.addAttribute("javaInfo", javaInfo.toString());
        model.addAttribute("osInfo", osInfo.toString());
        model.addAttribute("hostInfo", hostInfo.toString());
        model.addAttribute("total", total);
        model.addAttribute("available", available);
        model.addAttribute("jvmSpecInfo", jvmSpecInfo);
        FastParam fastParam = new FastParam();
        PageInfo<GongGao> pageInfo = gongGaoMapper.findByFastParam(fastParam);
        model.addAttribute("gonggaos", pageInfo.getList());
        return "sys/dashboard/index";
    }

}
